package com.rqf.ls.controller;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rqf.ls.service.ILawyerRecommendService;
import com.rqf.ls.service.IRegisterOfLawyerService;
import com.server.web.DataVector;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;
import com.server.web.RequestInput;

/**
 * 律师推荐
 * @author ServerZhang
 * @date 2016年3月28日
 */
@Controller
@RequestMapping("recommend")
public class LawyerRecommendController {
	
	@Autowired
	private ILawyerRecommendService recommendService;
	@Autowired
	private IRegisterOfLawyerService registerOfLawyerService;
	
	
	 /**
	 * 律师列表
	 * @param request
	 * @param response
	 * @author ServerZhang
	 * @date 2016年3月28日
	 */
	@RequestMapping("list")
	public void list(HttpServletRequest request, HttpServletResponse response){
		DataVector<Map<String, Object>> listData = recommendService.getList(new RequestInput(request));
		List<Map<String, Object>> list = listData.getList();
		Iterator<Map<String, Object>> iterator = list.iterator();
		while(iterator.hasNext()){
			Map<String, Object> next = iterator.next();
			Object phoneObj = next.get("PHONE");
			if (phoneObj != null) {
				next.put("imgPath", registerOfLawyerService.getPhotoPath(phoneObj.toString()));
			}
		}
		
		String json = JSONSerielizer.toJson(list, null, null);
		
		response.addHeader("Access-Control-Allow-Origin", "*");
		OutputUtil.returnString(response, json);
	}
	
}
